#pragma once
#include "Node.h"

const int STACK_SIZE = 100;

template <class TYPE>
class Stack
{
private:
	int count;
	NODE<TYPE> *top;

public:
	Stack();
	~Stack(void);
	bool pushStack(TYPE dataIn);
	bool popStack(TYPE& dataOut);
	bool stackTop(TYPE& dataOut);
	bool emptyStack();
	bool fullStack();
	int stackCount();
	void showStack();
};

template <class  TYPE>
Stack<TYPE>::Stack()
{
	top = nullptr;
	count = 0;
}

template <class  TYPE>
Stack<TYPE>::~Stack(void)
{
	NODE<TYPE> *temp = top;
	while(temp) {
		top = top->next;
		delete temp;
		temp = top;
	}
}

template <class  TYPE>
bool Stack<TYPE>::pushStack (TYPE dataIn) {
	bool success;
	NODE<TYPE> *newPtr;

	if(!(newPtr = new NODE<TYPE>))
		success = false;
	else {
		newPtr->data = dataIn;
		newPtr->next = top;
		top = newPtr;
		count++;
		success = true;
	}
	return success;
}

template <class  TYPE>
bool Stack<TYPE>::popStack (TYPE& dataOut) {
	bool success;
	NODE<TYPE> *delPtr;
	if(count == 0) success = false;
	else {
		dataOut = top->data;
		delPtr = top;
		top = top->next;
		delete delPtr;
		count--;
		success = true;
	}
	return success;
}

template <class TYPE>
bool Stack<TYPE>::stackTop(TYPE& dataOut) {
	bool success;
	if(count == 0) success = false;
	else {
		dataOut = top->data;
		success = true;
	}
	return success;
}

template <class TYPE>
bool Stack<TYPE>::emptyStack(){
	if(count == 0) return true;
	else return false;
}

template <class TYPE>
bool Stack<TYPE>::fullStack(){
	if(count == 0) return false;
	else {
		NODE *newPtr;
		if(!(newPtr = new NODE<TYPE>)) return true;
	}
}

template <class TYPE>
int Stack<TYPE>::stackCount() {
	return count;
}

template <class TYPE>
void Stack<TYPE>::showStack(){
	NODE<TYPE> *temp = top;
	while (temp)
	{
		cout<<temp->data<<" ";
		temp = temp->next;
	}
	cout<<endl;
}

